﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Framework;
using SchemaMonitor;



public enum EShow
{
	All = 0,
	Select = 1,
	ForPost = 2,
	ForTag = 3,
	XRated = 4,
	Delete = 5,
	Laptop = 6,
}
public enum EMenu
{
    Home = 0,
    Books = 1,
    Security = 2,
    Changes = 3,
    Data = 4,
    Checks = 5,
    Members = 6,
    Types = 7,
    Tags = 8,
    Photos = 9,
    Repeats = 10,
}

/// <summary>
/// Summary description for CSitemap
/// </summary>
public class CSitemap
{
	public CSitemap()
	{ }


	public static string Photo(long id) { return string.Concat("~/photo.aspx?id=", id); }
	public static string Photo(Guid md5) { return string.Concat("~/photo.aspx?md5=", md5); }


	public static string PhotoDetails(Guid md5) { return string.Concat("~/pages/photohashs/photohash.aspx?md5=", md5); }
	public static string PhotoHashAll() { return string.Concat("~/pages/photohashs/photohash.aspx"); }
	public static string PhotoHash(EShow show) { return string.Concat("~/pages/photohashs/photohash.aspx?show=", (int)show); }
	public static string PhotoAdd(EShow show, Guid md5) { return string.Concat(PhotoHash(show), "&add=", md5, "&p=", CWeb.RequestInt("p", CWeb.RequestInt("q", 1)), "&pageSize=", CWeb.RequestInt("pageSize", CWeb.RequestInt("ps",200))); }
	public static string PhotoRem(EShow show, Guid md5) { return string.Concat(PhotoHash(show), "&rem=", md5, "&p=", CWeb.RequestInt("p", CWeb.RequestInt("q", 1)), "&pageSize=", CWeb.RequestInt("pageSize", CWeb.RequestInt("ps", 200))); }
	public static string PhotoRepeats() { return string.Concat("~/pages/photohashs/repeats.aspx"); }

	public static string PhotoHash() { return "~/pages/photohashs/photoHash.aspx"; }
	public static string PhotoHash(int chapterId) { return string.Concat("~/pages/photohashs/photoHash.aspx?show=", (int)EShow.ForPost, "&chapterId=", chapterId); }
	public static string PhotoHashForTag(int tagId) { return string.Concat("~/pages/photohashs/photoHash.aspx?show=", (int)EShow.Select, "&tagId=", tagId); }


	public static string Home(int view) { return string.Concat("~/?view=", view); }


	public static string Tags(int tagTypeId, int tagId) { return string.Concat("~/?view=8&tagTypeId=", tagTypeId, "&tagId=", tagId); }
	public static string Tags(int tagTypeId) { return Tags(tagTypeId, 0); }

	#region Chapters
	//List/Search
	public static string ChaptersForSection(int sectionId) {   return string.Concat("~/?sectionId=", sectionId); }
    public static string ChaptersForNode(Guid nodeGuid) {   return string.Concat("~/pages/chapters/ForNode.aspx?nodeGuid=", nodeGuid); }
    public static string ChaptersForSection(int sectionId, string search) { return string.Concat(ChaptersForSection(sectionId), "&search=", Encode(search)); }
    public static string ChaptersForNode(Guid nodeGuid, string search) { return string.Concat(ChaptersForNode(nodeGuid), "&search=", Encode(search)); }


	public static string ChapterEdit(int chapterId) { return string.Concat("~/pages/chapters/chapter.aspx?chapterId=", chapterId); }
	public static string ChapterEdit(Guid nodeGuid) { return string.Concat("~/pages/chapters/chapter.aspx?nodeGuid=", nodeGuid); }
	

	//UserControls
	public static string UCChapter() { return "~/pages/chapters/usercontrols/UCChapter.ascx"; }
    #endregion

#region Sections
    //List/Search
    public static string Sections(             ) {   return "~/pages/sections/default.aspx"; }
    public static string Sections(string search) {   return string.Concat(CSitemap.Sections(), "?search=", Encode(search)); }
    public static string Sections(string search, CPagingInfo pi) {   return string.Concat(CSitemap.Sections(search), "&sortBy=", pi.SortByColumn, "&desc=", pi.Descending, "&p=", pi.PageIndex + 1); }
    
    //Add/Edit
    private static string SectionAddEdit()    {   return "~/pages/sections/section.aspx";   } 
    public static string SectionAdd()         {   return SectionAddEdit(); } //May need to add a parentId 
    public static string SectionEdit(int sectionId) {   return string.Concat("~/?menu=1&sectionId=", sectionId);    }
	public static string SectionEdit(CSection s) { return string.Concat(SectionEdit(s.SectionId), "&bookId=", s.SectionBookId); }
	public static string SectionView(int sectionId, int bookId) { return string.Concat(BookView(bookId), "&viewSectionId=", sectionId); }

	//Usercontrols (Dynamic)
	public static string UCSection()     {   return "~/pages//sections/usercontrols/UCSection.ascx"; } 

    //Folders (relative to /web project)
    public static string SectionUploads()     {   return "~/uploads/sections/"; }
	#endregion

	#region Books
	//List/Search
	public static string DataView(SchemaMonitor.CNode node) { return DataView(node.Root); }
	public static string DataView(SchemaMonitor.json.CNodeRoot root) { return DataView(root.Id, root.TypeId); }
	public static string DataView(string nodeId, int typeId) { return string.Concat("~/?typeId=", typeId, "&view=", 4, "&nodeId=", nodeId); }
	public static string DataEdit(string nodeId, int typeId) { return string.Concat(DataView(nodeId, typeId), "&edit=1"); }
	public static string Data(string nodeId, int typeId, bool isEdit = false) { return isEdit ? DataEdit(nodeId, typeId) : DataView(nodeId, typeId); }
	public static string Data(string search, int typeId) {   return string.Concat("~/?search=", Encode(search), "&typeId=", typeId, "&view=", 4); }
	public static string Data(string search, int typeId, CPagingInfo pi) {   return string.Concat(CSitemap.Data(search, typeId), "&sortBy=", pi.SortByColumn, "&desc=", pi.Descending, "&p=", pi.PageIndex + 1); }
    
    //Add/Edit
    private static string BookAddEdit()    {   return "~/pages/books/book.aspx";   } 
    public static string BookAdd()         {   return BookAddEdit(); } //May need to add a parentId 
    public static string BookEdit(int bookId)                         {   return string.Concat("~/?bookId=", bookId, "&sectionId=0&menu=1");    }
	public static string BookView(int bookId) { return string.Concat("~/?viewBookId=", bookId); }
	public static string BookExport(int bookId, bool noimgs = false) { return string.Concat(BookView(bookId), "&attach=true", noimgs ? "&noimgs=1" : ""); }

	//Usercontrols (Dynamic)
	public static string UCBook()     {   return "~/pages//books/usercontrols/UCBook.ascx"; } 

    //Folders (relative to /web project)
    public static string BookUploads()     {   return "~/uploads/books/"; }
	#endregion

	private static string Encode(string s)
	{
		return HttpUtility.UrlDecode(s);
	}

}